package com.woniuxy.controller;


import com.woniuxy.ResponseResult;
import com.woniuxy.entity.Dishinfo;
import com.woniuxy.service.DishinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.constraints.Min;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2021-03-23
 */
@Controller
@RequestMapping("/dishinfo/")
@Validated
public class DishinfoController {
    @Autowired
    private DishinfoService dishinfoService;

    @ResponseBody
    @GetMapping("getDishInfosBySid")
    public ResponseResult< List<Map<String, Object>>> getDishInfosBySid(@Min(value = 1,message = "商家id不能小于1") Integer sid){
        ResponseResult<List<Map<String, Object>>> result = new ResponseResult();
        List<Map<String, Object>> mapList = dishinfoService.getDishInfosBySid(sid);
        result.setCode(200);
        result.setMsg("成功");
        result.setData(mapList);
        return result;
    }

     @ResponseBody
     @GetMapping("getDetailDishInfo")
    public ResponseResult<Dishinfo> getDetailDishInfo(Integer id){
         Dishinfo detailDishInfo = dishinfoService.getDetailDishInfo(id);
         ResponseResult<Dishinfo> result = new ResponseResult<>();
         result.setCode(200);
         result.setMsg("成功");
         result.setData(detailDishInfo);
         return  result;
     }
      @ResponseBody
      @PutMapping("istake")
     public   ResponseResult isTake(Integer id){
          Integer result = dishinfoService.isTake(id);
          if(result>0){
              return ResponseResult.SUCCESS;
          }
          return ResponseResult.ERR;

      }
    @RequestMapping("getPriceById")
    @ResponseBody
    public BigDecimal getPriceById(Integer id){
        BigDecimal price = dishinfoService.getPriceById(id);
        return price;
    }



}

